#	$Id$
#
# Makefile.in for cpp
#
VPATH=@srcdir@
srcdir=@srcdir@
top_srcdir=@top_srcdir@
builddir=@builddir@
top_builddir=@top_builddir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libexecdir = @libexecdir@
datarootdir = @datarootdir@
mandir = @mandir@
CC = @CC@
EXEEXT = @EXEEXT@
CFLAGS = @CFLAGS@ @ADD_CFLAGS@
CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ \
	-I$(srcdir) -I$(top_builddir) -I$(builddir) -I$(MIPDIR) -I$(MDIR) \
	-I$(COMMONDIR) -DNVMPGS=4
LIBS = @LIBS@
LDFLAGS = @LDFLAGS@
YACC = @YACC@
YFLAGS = @YFLAGS@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
TARGMACH = @targmach@

MIPDIR=$(top_srcdir)/mip
MDIR=$(top_srcdir)/arch/$(TARGMACH)
COMMONDIR=$(top_srcdir)/common

DEST=@BINPREFIX@cpp$(EXEEXT)
MANPAGE=@BINPREFIX@cpp

all: $(DEST)

OBJS=	compat.o cpp.o cpc.o token.o
HDRS=	cpp.h

$(OBJS): $(HDRS)

compat.o: $(COMMONDIR)/compat.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(COMMONDIR)/compat.c

cpp.o: $(srcdir)/cpp.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/cpp.c

cpc.o: $(srcdir)/cpc.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/cpc.c

token.o: $(srcdir)/token.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/token.c

$(DEST): $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)

test: $(DEST)
	@for n in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ; do	\
		echo -n "test$${n} " ;					\
		./$(DEST) < tests/test$${n} > tests/run$${n} &&		\
		cmp tests/run$${n} tests/res$${n} && echo ;		\
		if test -f tests/res$${n}C ; then			\
			echo -n "test$${n}C " ;				\
			./$(DEST) -C < tests/test$${n} > tests/run$${n}C && \
			cmp tests/run$${n}C tests/res$${n}C && echo ;	\
		fi ;							\
	done

install:
	test -z "$(DESTDIR)$(libexecdir)" || mkdir -p "$(DESTDIR)$(libexecdir)"
	$(INSTALL_PROGRAM) $(DEST) $(DESTDIR)$(libexecdir)
	test -z "$(DESTDIR)$(mandir)/man1" || mkdir -p "$(DESTDIR)$(mandir)/man1"
	$(INSTALL_DATA) $(srcdir)/cpp.1 $(DESTDIR)$(mandir)/man1/$(MANPAGE).1

clean:
	rm -f $(OBJS) $(DEST) tests/run*

distclean: clean
	rm -f Makefile
